#-*- coding: utf-8 -*-
'''
Created on Aug 27, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, String, MetaData, Table
from sqlalchemy.orm import mapper
    
class ConfigPayment(object):

    _Mapper_ = None
    _company_id_ = -1
    _shop_id_ = -1    
    def __init__(self):
        self.id = 0
        self.mark = ''
        self.name = ''
        self.description = ''
        self.exchange_rate = 0
        self.is_valid = 0
        
    @staticmethod
    def doMapping(company_id, shop_id):
        '''
        按company_id分库，shop_id对应公司分店，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if ConfigPayment._company_id_ == company_id and ConfigPayment._shop_id_ == shop_id:
            return
                
        if ConfigPayment._Mapper_ is not None:
            ConfigPayment._Mapper_.dispose()
            
        metaData = MetaData()
        configPaymentTable = Table('config_payment', metaData,
                           Column('id', Integer, primary_key = True, autoincrement = True),
                           Column('mark', String),
                           Column('name', String),
                           Column('description', String),
                           Column('exchange_rate', Integer),
                           Column('is_valid', Integer),
                           schema = "shop_%s_%s" % (company_id, shop_id))
        
        ConfigPayment._Mapper_ = mapper(ConfigPayment, configPaymentTable)
    
